
{include file="public/header"/}
<link rel="stylesheet" href="{__PUBLIC_PATH}/admin/pcf/pcfbase1.css?v={$version}"/>
<script src="{__PUBLIC_PATH}/common/js/jquery.js?v={$version}"></script>
<script src="{__PUBLIC_PATH}/admin/pcf/global.js?v={$version}"></script>
</head>
<body>
<style>
  .layui-layer-content{height:auto!important;} 
  .layui-form-selected dl{z-index: 999999 !important;}
  .pcfwidth1{margin-top:5px;}
  @media screen and (max-width:1000px){
    .pcfwidth{width:100%!important;}
  }
  @media screen and (max-width:450px){
    .pcfwidth1{margin-top:0px!important;}
    .pcfshow{display:block!important;}
  }
</style>
<div class="layui-form" id="LAY-component-layer-list">
    <div class="layui-fluid" style="padding-bottom:83px;">
        <div class="layui-card">
        <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
          <div class="layui-form-item">
            <label class="layui-form-label">链接类型</label>
            <div class="layui-input-block">
                <input type="radio" name="typeid" lay-filter="typeid" value="1" title="文字" checked>
                <input type="radio" name="typeid" lay-filter="typeid" value="2" title="图片" >    
            </div>
          </div>
          <div class="layui-form-item layui-col-xs6 pcfwidth">
            <label class="layui-form-label"><b style="color:red;">*</b> 网址URL</label>
            <div class="layui-input-block">
             <input type="text" name="url" value="" lay-verify="required|url" placeholder="http://" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item layui-col-xs6 pcfwidth">
            <label class="layui-form-label"><b style="color:red;">*</b> 网站名称</label>
            <div class="layui-input-block">
             <input type="text" name="title" value="" class="layui-input" lay-verType="tips" lay-verify="required" required>
            </div>
          </div>
          <div class="layui-form-item typeid2 none">
              <label class="layui-form-label">上传Logo</label>
              <div class="layui-input-inline">
              <input name="logo" id="logo" placeholder="图片地址" value="" class="layui-input inp inp_logo">
              <img id="img_logo" src="{:get_default_pic()}" class="none">
              </div>
              <label class="layui-form-label none pcfshow"></label>
              <div class="layui-btn-group pcfwidth1">
                <input type="button" value="上传图片" class="layui-btn layui-btn-sm test-upload-demoMore" lay-data="{number:1,ey_inputId:'logo',ey_savepath:'allimg'}">
                <input type="button" value="选择图片" class="layui-btn layui-btn-sm" onClick="GetPictureFolder(1,'logo');">
                <input type="button" value="预览" class="layui-btn layui-btn-sm" onclick="BigImages($('#img_logo').attr('src'));">
                <input type="button" value="清除" class="layui-btn layui-btn-sm layui-btn-warm" data-inputid="logo" onclick="DelImages(this);">
              </div>
          </div>
          <div class="layui-form-item layui-col-xs6 pcfwidth">
            <label class="layui-form-label">站长Email</label>
            <div class="layui-input-block">
              <input type="text" name="email" value="" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item layui-col-xs6 pcfwidth">
            <label class="layui-form-label">网站备注</label>
            <div class="layui-input-block">
                <textarea name="intro" class="layui-textarea" placeholder="备注一些站长联系方式、信息等内容"></textarea>
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-inline">
              <input type="text" name="sort_order" value="100" lay-verify="number" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">新窗口打开</label>
            <div class="layui-input-inline">
                <input type="checkbox" lay-filter="target" lay-skin="switch" lay-text="是|否" checked>
                <input type="hidden" name="target" value="1"/>
            </div>
          </div>
        </div>
        </div>
        <div style="clear:both;"></div>
        </div>
    </div>
    <div class="submit-info text-center">
        <button class="layui-btn" lay-submit lay-filter="formSubmit">确认提交</button>
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
    </div>
</div>
{include file="public/footer"/}
<script>
  layui.use(['layer', 'form'], function () {
     var $ = layui.$,
        layer = layui.layer,
        form = layui.form;
        layer = layui.layer;
        form.render();
        // 监听开关
        form.on('switch', function(data){
          var elemId = data.elem.attributes['lay-filter']['nodeValue'];
          if (data.elem.checked) {
            this.value = 1;
          } else {
            this.value = 0;
          }
          $("input[name='"+elemId+"']").val(this.value);
        });
        // 监听单选项
        form.on('radio(typeid)', function(data){
            if (data.value == 2) {
                $('.typeid2').show();
            } else {
                $('.typeid2').hide();
            }
        });
        //监听提交
        form.on('submit(formSubmit)', function(data){
            layer.load(2);
            $.ajax({
                type : 'post',
                url : '{:url("/channel.links/add")}',
                data : data.field,
                dataType : 'json',
                success : function(res){
                    layer.closeAll('loading');
                    if(res.status){
                        layer.msg(res.msg, {icon: 1, time: 1000}, function(){
                            parent.window.location.href = res.url;
                        });
                    }else{
                        layer.msg(res.msg, {icon: 2, time: 1000});
                    }
                },
                error: function(e){
                    layer.closeAll('loading');
                    layer.msg("未知错误，操作中断！", {icon: 2, time: 1000});
                }
            });
            return false;
        })
    });
</script>
</body>
</html>